import { CodeListService } from '../app/codelist-service';
import { EntityBaseService, IContext, HttpResponse } from 'ibiz-core';
import { ICHARTENTITY, CHARTENTITY } from '../../entities';
import keys from '../../entities/chartentity/chartentity-keys';
import { CHARTENTITYDTOHelp } from '../../entities/chartentity/chartentitydto-help';


/**
 * 图表实体服务对象基类
 *
 * @export
 * @class CHARTENTITYBaseService
 * @extends {EntityBaseService}
 */
export class CHARTENTITYBaseService extends EntityBaseService<ICHARTENTITY> {
    protected get keys(): string[] {
        return keys;
    }
    protected SYSTEMNAME = 'ActiveTYYW';
    protected APPNAME = 'App2';
    protected APPDENAME = 'CHARTENTITY';
    protected APPWFDENAME = 'CHARTENTITY';
    protected APPDENAMEPLURAL = 'CHARTENTITies';
    protected dynaModelFilePath:string = 'PSSYSAPPS/App2/PSAPPDATAENTITIES/CHARTENTITY.json';
    protected APPDEKEY = 'chartentityid';
    protected APPDETEXT = 'chartentityname';
    protected quickSearchFields = ['chartentityname',];
    protected selectContextParam = {
    };

    constructor(opts?: any) {
        super(opts, 'CHARTENTITY');
    }

    newEntity(data: ICHARTENTITY): CHARTENTITY {
        return new CHARTENTITY(data);
    }

    /**
     * Create
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async Create(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data = await this.beforeExecuteAction(_context,_data,'Create');
        if (!_data.srffrontuf || _data.srffrontuf != 1) {
            _data[this.APPDEKEY] = null;
        }
        if (_data.srffrontuf != null) {
            delete _data.srffrontuf;
        }
    _data = await CHARTENTITYDTOHelp.get(_context,_data);
        const res = await this.http.post(`/chartentities`, _data);
        res.data = await CHARTENTITYDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Get
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async Get(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/chartentities/${encodeURIComponent(_context.chartentity)}`, _data);
        res.data = await CHARTENTITYDTOHelp.set(_context,res.data);
        res.data = await this.afterExecuteAction(_context,res?.data,'Get');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * GetDraft
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async GetDraft(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data[this.APPDENAME?.toLowerCase()] = undefined;
        _data[this.APPDEKEY] = undefined;
        const res = await this.http.get(`/chartentities/getdraft`, _data);
        res.data = await CHARTENTITYDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Remove
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async Remove(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.delete(`/chartentities/${encodeURIComponent(_context.chartentity)}`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Update
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async Update(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        _data = await this.beforeExecuteAction(_context,_data,'Update');
    _data = await CHARTENTITYDTOHelp.get(_context,_data);
        const res = await this.http.put(`/chartentities/${encodeURIComponent(_context.chartentity)}`, _data);
        res.data = await CHARTENTITYDTOHelp.set(_context,res.data);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchDefault
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async FetchDefault(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/chartentities/fetchdefault`, _data);
        res.data = await CHARTENTITYDTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchDefault');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchSet1
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async FetchSet1(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/chartentities/fetchset1`, _data);
        res.data = await CHARTENTITYDTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchSet1');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * FetchSet2
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async FetchSet2(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/chartentities/fetchset2`, _data);
        res.data = await CHARTENTITYDTOHelp.ToDataObjArray(_context,res.data);
        res.data = await this.afterExecuteActionBatch(_context,res?.data,'FetchSet2');
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
    /**
     * Select
     *
     * @param {*} [_context={}]
     * @param {*} [_data = {}]
     * @returns {Promise<HttpResponse>}
     * @memberof CHARTENTITYService
     */
    async Select(_context: any = {}, _data: any = {}): Promise<HttpResponse> {
        try {
        const res = await this.http.get(`/chartentities/${encodeURIComponent(_context.chartentity)}/select`);
        return res;
            } catch (error) {
                return this.handleResponseError(error);
            }
    }
}
